using System;
using System.Threading;
using System.Resources;


namespace cmdSharePointExtractor
{
	/// <summary>
	/// Summary description for Parameters.
	/// </summary>
	public class Parameters
	{
		private ResourceManager rm=null;
		public Parameters()
		{
			rm = ResourceManager.CreateFileBasedResourceManager("strings", ".", null);
		}

		/// <summary>
		/// This method processes the commandline arguments
		/// </summary>
		public bool ReadParameters(string[] args)
		{
			bool returnValue=true;
			for(int i=0;i<args.GetLength(0);i+=2)
			{
				string lowerarg=args[i].ToLower();
				string data=args[i+1];
				switch(lowerarg)
				{

					case "-url":
						SiteURL=args[i+1];
						break;
					case "-newname":
						NewName=args[i+1];
						break;
					case "-list":
						List=args[i+1];
						break;
					case "-out":
						OutputDirectory=args[i+1];
						break;
					case "-owner":
						owner=args[i+1];
						break;
					case "-contact":
						contact=args[i+1];
						break;
					case "-type":
						SiteType=args[i+1];
						break;
					case "-desttype":
						DestSiteType=args[i+1];
						break;
					case "-root":
						Root=args[i+1];
						break;
					case "-folder":
						Folder=args[i+1];
						break;
					case "-includesubwebs":
						IncludeSubWebs=bool.Parse(args[i+1]);
						break;
					case "-extractusers":
						ExtractUsers=bool.Parse(args[i+1]);
						break;
					case "-extractdesign":
						ExtractUsers=bool.Parse(args[i+1]);
						break;
					case "-extractversions":
						ExtractVersions=bool.Parse(args[i+1]);
						break;
					case "-extractids":
						ExtractIDs=bool.Parse(args[i+1]);
						break;
					case "-threshold":
						Threshold=DateTime.Parse(args[i+1]);
						break;


				}
			}
			if(SiteURL.Length==0 || NewName.Length==0 || OutputDirectory.Length==0)
			{
				returnValue=false;
			}
			else
				returnValue=true;




			return returnValue;
		}

		#region properties

		private string siteURL;

		/// <summary>
		/// This is the URL to the SharePoint site/area to be extracted
		/// </summary>
		public string SiteURL
		{
			get
			{
				return siteURL;
			}
			set
			{
				siteURL=value;
			}
		}
		private bool includeSubWebs=true;

		/// <summary>
		/// This is a boolean flag indicating whether subwebs should be processed
		/// </summary>
		public bool IncludeSubWebs
		{
			get
			{
				return includeSubWebs;
			}
			set
			{
				includeSubWebs=value;
			}
		}

		private bool extractDesign=false;

		/// <summary>
		/// This is a boolean flag indicating whether design elements should be processed
		/// </summary>
		public bool ExtractDesign
		{
			get
			{
				return extractDesign;
			}
			set
			{
				extractDesign=value;
			}
		}

		private bool extractVersions=true;
		/// <summary>
		/// This is a boolean flag indicating whether versions should be processed
		/// </summary>
		public bool ExtractVersions
		{
			get
			{
				return extractVersions;
			}
			set
			{
				extractVersions=value;
			}
		}


		private string newName;

		/// <summary>
		/// This is the name of the new site/area
		/// </summary>
		public string NewName
		{
			get
			{
				return newName;
			}
			set
			{
				newName=value;
			}
		}

		private string root;
		/// <summary>
		/// This is the name of the root container
		/// </summary>
		public string Root
		{
			get
			{
				return root;
			}
			set
			{
				int pos=value.IndexOf("/");

				if(pos==-1)
					root=value;
				else
				{
					
					


					string message=rm.GetString("RootArgEx");//"The value for Rootcannot contain \"/\"";
					ArgumentException argEx=new ArgumentException(message,"Root");
					throw argEx;
				}

			}
		}
	

		private string outputDirectory;

		/// <summary>
		/// This is the name of the output directory
		/// </summary>
		public string OutputDirectory
		{
			get
			{
				return outputDirectory;
			}
			set
			{
				outputDirectory=value;
			}
		}

		private string list;

		/// <summary>
		/// This is the optional list parameter
		/// </summary>
		public string List
		{
			get
			{
				return list;
			}
			set
			{
				list=value;
			}
		}
		private string siteType;

		/// <summary>
		/// This is the name of the output directory
		/// </summary>
		public string SiteType
		{
			get
			{
				return siteType;
			}
			set
			{
				if(value=="Site" || value == "Area")
					siteType=value;
				else
				{
					string message=rm.GetString("SiteTypeArgEx");//The value for SiteType must be either \"Site\" or \"Area\"
					ArgumentException argEx=new ArgumentException(message,"SiteType");
					throw argEx;
				}
			}
		}
		private string destSiteType;

		/// <summary>
		/// This is the name of the output directory
		/// </summary>
		public string DestSiteType
		{
			get
			{
				return destSiteType;
			}
			set
			{
				if(value=="Site" || value == "Area")
					destSiteType=value;
				else
				{
					string message=rm.GetString("SiteTypeArgEx");//The value for SiteType must be either \"Site\" or \"Area\"
					ArgumentException argEx=new ArgumentException(message,"DestSiteType");
					throw argEx;
				}
			}
		}

		private string owner=Thread.CurrentPrincipal.Identity.Name;
		public string Owner
		{
			get
			{
				return owner;
			}
			set
			{
				owner=value;
			}
		}

		private string contact="";
		public string Contact
		{
			get
			{
				return contact;
			}
		}
		private string folder="";

		/// <summary>
		/// This is the Folder that will be extracted
		/// </summary>
		public string Folder
		{
			get
			{
				return folder;
			}
			set
			{
				folder=value;
			}
		}

		private DateTime dateThreshhold;

		/// <summary>
		/// 
		/// </summary>
		public DateTime DateThreshhold
		{
			get
			{
				return dateThreshhold;
			}
			set
			{
				dateThreshhold=value;
			}
		}



		private bool extractUsers=true;

		/// <summary>
		/// Boolean flag indication if user data will be extracted
		/// </summary>
		public bool ExtractUsers
		{
			get
			{
				return extractUsers;
			}
			set
			{
				extractUsers=value;
			}
		}
		private bool showInSiteDir=false;

		/// <summary>
		/// Boolean flag indication if the site will be added to the SiteDirectory
		/// </summary>
		public bool ShowInSiteDir
		{
			get
			{
				return showInSiteDir;
			}
			set
			{
				showInSiteDir=value;
			}
		}
		#endregion

		private DateTime threshold=DateTime.MinValue;

		/// <summary>
		/// This is the threshold that can be used in partial migrations
		/// </summary>
		public DateTime Threshold
		{
			get
			{
				return threshold;
			}
			set
			{
				threshold=value;
			}
		}

		private bool extractIDs;

		/// <summary>
		/// This flag controls if the List IDs are exported
		/// </summary>
		public bool ExtractIDs
		{
			get
			{
				return extractIDs;
			}
			set
			{
				extractIDs=value;
			}
		}

	}
}
